package com.lagou.service;

import com.lagou.common.pojo.Result;
import com.lagou.dao.ResumeDao;
import com.lagou.common.pojo.Resume;
import com.lagou.common.utils.ResultUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * desc:
 *
 * @author tengfei wang
 * @version 1.0
 * @date Created in 16/9/2020
 */
@Service
public class ResumeServiceImpl implements ResumeService {

    @Resource
    private ResumeDao resumeDao;

    @Override
    public Result getResumeList() {
        return ResultUtils.success(resumeDao.findAll());
    }


    @Override
    public Result getResumeById(Integer id) {
        Optional<Resume> resume = resumeDao.findById(id);
        return ResultUtils.success(resume.orElse(null));
    }

    @Override
    public Result addResume(Resume resume) {
        return ResultUtils.success(resumeDao.save(resume));
    }

    @Override
    public Result updateResume(Resume resume) {
        return ResultUtils.success(resumeDao.save(resume));
    }

    @Override
    public Result deleteResume(Integer id) {
        Optional<Resume> resume = resumeDao.findById(id);
        if (!resume.isPresent()) {
            return ResultUtils.error(500, "请求删除对象未找到");
        }
        resumeDao.delete(resume.get());
        return ResultUtils.success();
    }
}
